﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using BCDto.MakeStaticPagingComponent.MakeStaticPaging;
using BCService.MakeStaticPagingComponent;
using BCDto.MakeStaticPagingComponent.PageTemplate;

namespace BCTMSRESTful.Controllers.Management.MakeStaticPagingComponent
{
    /// <summary>
    /// 构建静态页面模板控制器
    /// </summary>
    [ApiExplorerSettings(GroupName = "MakeStaticPage")]
    [Route("api/v1/sim/[controller]")]
    public class MakeStaticPagingController : ManagementBaseController
    {
        private readonly IMakeStaticPagingService makeStaticPagingService;

        public MakeStaticPagingController(IMakeStaticPagingService makeStaticPagingService)
        {
            this.makeStaticPagingService = makeStaticPagingService;
        }

        /// <summary>
        /// 获取系统页面列表
        /// </summary>
        /// <response code="200">返回网站配置服务信息。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(IEnumerable<MakeStaticPagingTaskDto>), 200)]
        public IActionResult GetSystemPagingList()
        {
            return this.Ok(this.makeStaticPagingService.GetSystemPagingList());
        }
        
        /// <summary>
        /// 更新系统分页列表页面总记录数
        /// </summary>
        /// <param name="pageTemplateId">页面模板Id</param>
        /// <response code="200">返回网站配置服务信息。</response>
        /// <returns></returns>
        [HttpPut("[action]/{page_template_id}")]
        [ProducesResponseType(typeof(PageTemplateDto), 200)]
        public IActionResult PagingTotal([FromRoute(Name = "page_template_id")]long pageTemplateId)
        {
            return this.Ok(this.makeStaticPagingService.GetPagingListInfo(pageTemplateId));
        }

        /// <summary>
        /// 更新系统内容页面总记录数
        /// </summary>
        /// <param name="pageTemplateId">页面模板Id</param>
        /// <response code="200">返回网站配置服务信息。</response>
        /// <returns></returns>
        [HttpGet("[action]/{page_template_id}")]
        [ProducesResponseType(typeof(PageTemplateDto), 200)]
        public IActionResult ContentTotal([FromRoute(Name = "page_template_id")]long pageTemplateId)
        {
            return this.Ok(this.makeStaticPagingService.GetContentPagingInfo(pageTemplateId));
        }

        /// <summary>
        /// 生成静态页面
        /// </summary>
        /// <param name="pageTemplateId">页面模板Id</param>
        /// <param name="index">当前页码</param>
        /// <response code="200">返回页面是否生成成功。</response>
        /// <returns></returns>
        [HttpPost("[action]")]
        [ProducesResponseType(typeof(bool), 200)]
        public IActionResult CreateStaticPaging([FromQuery(Name ="page_template_id")]long pageTemplateId,
            [FromQuery(Name ="index")]int? index)
        {
            this.makeStaticPagingService.MakeStaticPaging(pageTemplateId,index);
            return this.Ok(true);
        }
    }
}
